
import Vue from 'vue'

let forbidClick = null;
export default {
    bind(e) {
        const el = e;
        let timer = null;
        forbidClick = () => {
            el.disabled = true;
            el.classList.add('is-disabled');
            let iconDom = el.childNodes[1];
            let i = document.createElement("i");
            i.classList.add('el-icon-loading');
         
            el.replaceChild(i, el.childNodes[1]);
        
            timer = setInterval(() => {
                if (window.currentResq.done) {
                  
                    clearInterval(timer);
                    el.disabled = false;
                  
                    el.classList.remove('is-disabled');
                 
                    el.replaceChild(iconDom, el.childNodes[1]);
                  
                }
            }, 500);
          
        };
        el.addEventListener('click', forbidClick);
    },
    unbind() {
        
        document.removeEventListener('click', forbidClick);
    },
};
//防抖处理 对v-on做处理
const on = Vue.prototype.$on
Vue.prototype.$on = function (event, func) {
    let timer;
    let flag = true;
    let newFunc = func
    if (event == 'click') {
        newFunc = function () {
            if (flag) {
                func.apply(this, arguments)
                flag = false
            }
            clearTimeout(timer)
            timer = setTimeout(function () {
                flag = true
            }, 500)
        }
    }
    on.call(this, event, newFunc)
}